package com.janko.starter;

import com.janko.properties.DemoProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.janko.services.DemoService;

/**
 * @Author nyk
 * @Date 2021/6/28 10:59
 * @Version 1.0
 * @Desc 自定义装配类
 */
@Configuration
@EnableConfigurationProperties(DemoProperties.class)
@ConditionalOnProperty(
        prefix = "demo"
        ,name = "newStarter"
        ,havingValue = "true"
        ,matchIfMissing = true //当配置文件中example.service.enabled=true时进行自动配置，如果没有设置此值就默认使用matchIfMissing对应的值
)
public class newStarter {
    static {
        System.out.println("newStarter 启动成功");
    }
    @Autowired
    private DemoProperties demoProperties;

    @Bean(name = "demo")
    public DemoService demoService() {
        return new DemoService(demoProperties.getVarKey(), demoProperties.getVarValue(), demoProperties.getVarIsDelete());
    }
}
